import { GAlertWin } from "../../../../../com/mui/controls/GAlertWin";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { BaseWindow } from "../../../../component/window/BaseWindow";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class CheckBoxWin
    
    export  class CheckBoxWin extends GAlertWin
    {
        constructor(arg1: number, arg2: number)
        {
            super(arg1, arg2);
            return;
        }

        protected /* override */ createChildren(): void
        {
            if (Alert.title == null) 
            {
                title = GlobalClass.getBitmap(ImagesConst.Title_Tips);
            }
            super.createChildren();
            this.checkBox = new GCheckBox();
            this.checkBox.styleName = "GCheckBox";
            this.checkBox.label = Alert.checkBoxLabel;
            this.checkBox.textField.textColor = 65280;
            this.checkBox.width = 120;
            this.checkBox.height = 22;
            return;
        }

        protected /* override */ showCloseBtn(): void
        {
            return;
        }

        protected /* override */ childrenCreated(): void
        {
            var loc10=null;
            if (typeof !(Alert.title === "string")) 
            {
                if (Alert.title) 
                {
                    title = Alert.title;
                }
                else 
                {
                    title = GlobalClass.getBitmap("Title_Tips");
                }
            }
            message.multiline = true;
            message.htmlText = Alert.text;
            var loc1=new Object /* flash.display.Sprite */();
            var loc2=allButtons.length;
            var loc3=0;
            while (loc3 < loc2) 
            {
                (loc10 = allButtons[loc3]).addEventListener(flash.events.MouseEvent.CLICK, this.buttonClickHandler);
                loc1.addChild(loc10);
                loc10.x = loc3 * (Alert.buttonWidth + 25);
                ++loc3;
            }
            var loc4;
            (loc4 = new Object /* flash.display.Sprite */()).addChild(message);
            if (icon) 
            {
                loc4.addChild(icon);
                message.x = icon.width + 15;
            }
            var loc5=boarderWidth * 2 + 10;
            var loc6;
            if ((loc6 = Math.max(title.width + loc5, message.width + loc5, loc1.width + loc5, minWidth)) < 260) 
            {
                loc6 = 260;
            }
            var loc7=60 + message.height + Alert.buttonHeight + 55;
            var loc8;
            (loc8 = ResouceConst.getScaleBitmap("WindowCenterB")).width = loc6 - 34;
            loc8.height = loc7 - 52;
            loc8.x = 17;
            loc8.y = 41;
            message.x = loc8.x + loc8.width / 2 - message.width / 2;
            message.y = 55;
            loc1.x = (loc6 - (Alert.buttonWidth + 25) * allButtons.length + 25) / 2;
            loc1.y = 60 + message.height + 10;
            boarder.width = loc6;
            boarder.height = 150;
            _promptBackground = new BaseWindow();
            (_promptBackground as BaseWindow).titleHeight = 30;
            (_promptBackground as BaseWindow).closeBtn.visible = false;
            var loc9;
            if ((loc9 = getButtonFlagsList())[3] != 1) 
            {
            };
            prompt = new Object /* flash.display.Sprite */();
            prompt.addChild(_promptBackground);
            title.y = (30 - title.height) / 2;
            title.x = (loc6 - title.width) / 2;
            (_promptBackground as BaseWindow).setSize(loc6, loc7);
            if (typeof Alert.title === "string") 
            {
                (_promptBackground as BaseWindow).title = Alert.title;
            }
            addChild(background);
            prompt.addChild(title);
            prompt.addChild(loc8);
            prompt.addChild(message);
            if (icon) 
            {
                addChild(icon);
            }
            prompt.addChild(loc1);
            addChild(prompt);
            prompt.addChild(this.checkBox);
            this.checkBox.x = 35;
            this.checkBox.y = loc7 - 38;
            if (Alert.showCloseBtn) 
            {
                closeBtn = new GButton();
                closeBtn.styleName = "CloseButton";
                closeBtn.setSize(19, 19);
                closeBtn.label = "";
                closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCloseBtnClickHandler);
                prompt.addChild(closeBtn);
                closeBtn.x = loc6 - closeBtn.width - 8;
                closeBtn.y = 7;
            }
            prompt.x = (stageWidth - prompt.width) / 2;
            prompt.y = (stageHeight - prompt.height) / 2;
            return;
        }

        protected /* override */ createButtons(): Vector.<GButton>
        {
            var loc1=new Vector.<GButton>();
            var loc2=getButtonFlagsList();
            if (loc2[0] == 1) 
            {
                loc1.push(this.CreateButton(Alert.yesLabel, Alert.YES));
            }
            if (loc2[1] == 1) 
            {
                loc1.push(this.CreateButton(Alert.noLabel, Alert.NO));
            }
            if (loc2[2] == 1) 
            {
                loc1.push(this.CreateButton(Alert.okLabel, Alert.OK));
            }
            if (loc2[3] == 1) 
            {
                loc1.push(this.CreateButton(Alert.calcelLabel, Alert.CANCEL));
            }
            return loc1;
        }

        protected /* override */ buttonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            while (loc1 < allButtons.length) 
            {
                allButtons[loc1].removeEventListener(flash.events.MouseEvent.CLICK, this.buttonClickHandler);
                ++loc1;
            }
            removeDragHandleer();
            this.parent.removeChild(this);
            if (closeHandler != null) 
            {
                if (extendObj == null) 
                {
                    closeHandler(Number(arg1.target.name.substr(4)), this.checkBox.selected);
                }
                else 
                {
                    closeHandler(Number(arg1.target.name.substr(4)), extendObj, this.checkBox.selected);
                }
            }
            return;
        }

        protected /* override */ onCloseBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=0;
            if (closeHandler != null) 
            {
                loc1 = getButtonFlagsList();
                loc2 = Alert.CANCEL;
                if (loc1[1] == 1) 
                {
                    loc2 = Alert.NO;
                }
                if (loc1[3] == 1) 
                {
                    loc2 = Alert.CANCEL;
                }
                if (extendObj == null) 
                {
                    closeHandler(loc2, this.checkBox.selected, true);
                }
                else 
                {
                    closeHandler(loc2, extendObj, this.checkBox.selected, true);
                }
                closeHandler = null;
            }
            super.onCloseBtnClickHandler(arg1);
            return;
        }

        /* internal  */CreateButton(arg1: string, arg2: int): GButton
        {
            var loc1=new GButton();
            loc1.label = arg1;
            loc1.width = Alert.buttonWidth;
            loc1.height = Alert.buttonHeight;
            loc1.name = "btn_" + arg2;
            if (Alert.buttonStyleName) 
            {
                loc1.styleName = Alert.buttonStyleName;
            }
            else 
            {
                loc1.styleName = "Button";
            }
            return loc1;
        }

        /* internal  */getBtnByName(arg1: int): GButton
        {
            var loc1=null;
            var loc2=0;
            var loc3=allButtons;
            for(loc1 of loc3) 
            {
                if (loc1.name != "btn_" + arg1) 
                {
                    continue;
                }
                return loc1;
            }
            return null;
        }

        protected /* var */checkBox: GCheckBox;
    }
